﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.IO;
using System.Web;

namespace mal.balades.Business.Helper
{
   public class JavascriptHelper
   {
       #region Fields
       private ScriptManager scriptManager;
       #endregion

       #region Construction / Destruction
       public JavascriptHelper(ScriptManager scriptManager)
       {
           if (scriptManager == null)
               throw new ArgumentNullException("scriptManager");
           this.scriptManager = scriptManager;
       }
       #endregion

       #region enum, struct, class

       #endregion

       #region Properties

       #endregion

       #region Methods
       public void BuildScript(string scriptVirtualPath)
       {
           string mapPath = HttpContext.Current.Server.MapPath(scriptVirtualPath);

           DirectoryInfo directory = new DirectoryInfo(mapPath);

#if DEBUG

           foreach (FileInfo js in directory.GetFiles("*.js"))
           {
               string url = string.Format("{0}/{1}", scriptVirtualPath, js.Name); 
               this.scriptManager.Scripts.Add(new ScriptReference(url));
           }
#else
           this.scriptManager.CompositeScript.ScriptMode = ScriptMode.Release;

            foreach (FileInfo js in directory.GetFiles("*.js"))
            {
                  string url = string.Format("{0}/{1}", scriptVirtualPath, js.Name);
                  this.scriptManager.CompositeScript.Scripts.Add(new ScriptReference(url));
            }
#endif

           foreach (FileInfo service in directory.GetFiles("*.svc"))
           {
               string url = string.Format("{0}/{1}", scriptVirtualPath, service.Name); 
               this.scriptManager.Services.Add(new ServiceReference(url));
           }
       }
       #endregion

       #region Events

       #endregion


   }
}
